home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
system_1
/
frmsysme.frm
(
.txt
)
next >
Wrap
Visual Basic Form
|
1998-10-13
|
6KB
|
119 lines
VERSION 5.00
Begin VB.Form frmSysMenu
AutoRedraw = -1 'True
Caption = "System Menu Demo"
ClientHeight = 2970
ClientLeft = 2370
ClientTop = 1425
ClientWidth = 6045
Icon = "frmSysMenu.frx":0000
LinkTopic = "Form1"
ScaleHeight = 198
ScaleMode = 3 'Pixel
ScaleWidth = 403
Begin VB.CommandButton Command1
Caption = "&Exit"
Height = 390
Left = 330
TabIndex = 2
Top = 2340
Width = 750
End
Begin VB.Label Label2
Caption = "Now try to move me, I dare you! And don't even think about trying to change my size because you can't!"
Height = 495
Left = 360
TabIndex = 1
Top = 1200
Width = 5295
End
Begin VB.Label Label1
Caption = "Check out my system menu. Click on my icon in the upper left corner."
Height = 375
Left = 360
TabIndex = 0
Top = 600
Width = 5295
End
Attribute VB_Name = "frmSysMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' demo project showing how to manipulate a form's system menu
' by Bryan Stafford of New Vision Software
- newvision@imt.net
' this demo is released into the public domain "as is" without
' warranty or guaranty of any kind. In other words, use at
' your own risk.
Private Const SC_SIZE As Long = &HF000&
Private Const SC_MOVE As Long = &HF010&
Private Const SC_CLOSE As Long = &HF060&
Private Const SC_MINIMIZE As Long = &HF020&
Private Const SC_MAXIMIZE As Long = &HF030&
Private Const SC_NEXTWINDOW As Long = &HF040&
Private Const SC_PREVWINDOW As Long = &HF050&
Private Const MF_BYCOMMAND As Long = &H0&
Private Const MF_STRING As Long = &H0&
Private Const MF_SEPARATOR As Long = &H800&
Private Const GWL_WNDPROC As Long = (-4&)
Private Declare Function GetSystemMenu& Lib "user32" (ByVal hWnd&, ByVal bRevert&)
Private Declare Function DeleteMenu& Lib "user32" (ByVal hMenu&, _
ByVal nPosition&, ByVal wFlags&)
Private Declare Function AppendMenu& Lib "user32" Alias "AppendMenuA" (ByVal hMenu&, _
ByVal wFlags&, ByVal wIDNewItem&, lpNewItem As Any)
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, _
ByVal nIndex&, ByVal dwNewLong&)
Private Sub Command1_Click()
' the user want's out, so let them out
Unload Me
End Sub
Private Sub Form_Load()
' set the wait cursor in case loading the form takes a while
Screen.MousePointer = vbHourglass
Dim hSysMenu&
' first thing to do is get the handle to the system menu for this form
hSysMenu = GetSystemMenu(hWnd, False)
' the following removes the close, size, move and maximize items from the system menu.
' we don't really care whether or not there is an error so we'll throw away the return value
' Note: make sure that you don't show the form before the 'Close' menu item is removed. If
' you do the close button on the titlebar will not be drawn in the disable state.
Call DeleteMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND)
Call DeleteMenu(hSysMenu, SC_SIZE, MF_BYCOMMAND)
Call DeleteMenu(hSysMenu, SC_MOVE, MF_BYCOMMAND)
Call DeleteMenu(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND)
' now we'll add the about item to the bottom of the menu. I've left in a commented call to
' append a separator incase you decide to remove the call to delete the close item from the menu.
' Since we have the last item in AppendMenu declared "As Any" to allow the use of either
' string or long paramiters, we need to add the byval so that each will be passed correctly.
' one last thing, the amprasand character (&) in the string being assigned to the menus
' tells windows to underline the following character in the string which allows the menu item
' to be selected by pressing the corrosponding key on the keybord
'Call AppendMenu(hSysMenu, MF_SEPARATOR, False, ByVal 0&)
Call AppendMenu(hSysMenu, MF_STRING, IDM_ABOUT, ByVal "&About...")
' add some more fun stuff
Call AppendMenu(hSysMenu, MF_SEPARATOR, False, ByVal 0&)
Call AppendMenu(hSysMenu, MF_STRING, IDM_WHO, ByVal "&Who Did This Anyway?")
' take control of message processing by installing our message handling
' routine into the chain of message routines for this window
procOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf MenuProc)
' reset the cursor
Screen.MousePointer = vbDefault
cantgetsysmenu:
' simple error handler
If Err Then
Err.Clear
MsgBox "Unable to load append system menu.", vbExclamation, "System Menu Demo"
Resume cantgetsysmenu
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' give message processing control back to VB
' if you don't do this you WILL crash!!!
Call SetWindowLong(hWnd, GWL_WNDPROC, procOld)
End Sub